www.gusucode.com > 24Beta 虚拟主机版 1.0.0 Beta源码程序 > 24Beta 虚拟主机版 1.0.0 Beta源码程序/24Beta-1.0.0-vhost/protected/controllers/SiteController.php

    <?php

class SiteController extends CController
{
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image
			'captcha' => array(
				'class'=>'application.extensions.CdcCaptchaAction',
				'backColor' => 0xFFFFFF,
				'height' => 22,
				'width' => 70,
				'maxLength' => 4,
				'minLength' => 4,
		        'foreColor' => 0xFF0000,
		        'padding' => 3,
		        'testLimit' => 1,
			),
		);
	}

    public function actionAjaxVerifyCode() 
	{
	    if (!app()->request->isAjaxRequest || !app()->request->isPostRequest) {
			echo '非法请求';
			exit();
		}
		
		if (user()->checkAccess('noValidateCode')) {
		    $data['error'] = 0;
		    echo json_encode($data);
		    exit(0);
		}
		
	    $clientCode = trim($_POST['clientCode']);
	    
		if (CdcBetaTools::validateCode($clientCode)) {
	        $data['error'] = 0;
	    } else {
	        $data['error'] = 1;
	        $data['message'] = '验证码不正确,请重新输入';
	    }
	    echo json_encode($data);
	}


	/**
	 * Displays the login page
	 */
	public function actionLogin()
	{
		$form=new LoginForm;
		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$form->attributes=$_POST['LoginForm'];
			// validate user input and redirect to previous page if valid
			if($form->validate())
				$this->redirect(Yii::app()->user->returnUrl);
		}
		// display the login form
		$this->render('login',array('form'=>$form));
	}

	/**
	 * Logout the current user and redirect to homepage.
	 */
	public function actionLogout()
	{
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->homeUrl);
	}
	
	public function actionTest()
	{
	    echo user()->name;exit;
	    $this->render('test');
	}
	
	public function actionUpload()
	{
	    if (!app()->request->isPostRequest) {
			header('HTTP/1.1 500  非法访问');
	        exit(0);
		}
    	if (isset($_POST["PHPSESSID"])) {
    	    // 关闭当前session,使用传递过来的session_id启动新的session
    	    app()->session->close();
    		session_id($_POST["PHPSESSID"]);
    	}
    	
	    if (!user()->checkAccess('uploadFiles')) {
			header('HTTP/1.1 500  没有上传权限');
	        exit(0);
		}
		
	    $file = CUploadedFile::getInstanceByName('swfupload');
	    if ($file->hasError) {
	        header('HTTP/1.1 500  上传错误');
	        exit(0);
	    }
	    $strDatePath = date('Y/m/d/', $_SERVER['REQUEST_TIME']);
	    $path = param('uploadBasePath') . $strDatePath;
        if (!file_exists($path) && !mkdir($path, 0755, true)) {
            header("HTTP/1.1 500 {$path} 目录不存在并且无法创建");
	        exit(0);
        } else if (!is_writable($path)) {
            header("HTTP/1.1 500 {$path} 目录不可写");
            exit(0);
        }
        
        $filename = $_SERVER['REQUEST_TIME'] . uniqid() . ($file->extensionName ? '.' . $file->extensionName : '');
        $fileSavePath = $path . $filename;
        if (!$file->saveAs($fileSavePath)) {
            header("HTTP/1.1 500 {$fileSavePath} 文件保存失败");
            exit(0);
        }
        echo param('uploadBaseUrl') . $strDatePath . $filename;
	}
	
	public function actionRss()
	{
	    header('Content-type: text/xml; charset=' . app()->charset);
	    $posts = Post::model()->getRssPosts(param('rssPostNums'));
	    $this->renderPartial('rss', array(
	        'posts' => $posts,
	    ));
	}
	
	public function actionAtom()
	{
	    header('Content-type: text/xml; charset=' . app()->charset);
	    $posts = Post::model()->getRssPosts(param('rssPostNums'));
	    $this->renderPartial('atom', array(
	        'posts' => $posts,
	    ));
	}
	
	public function actionSitemap()
	{
	    header('Content-type: text/xml; charset=' . app()->charset);
	    $posts = Post::model()->getRssPosts(param('sitemapPostNums'));
	    $this->renderPartial('sitemap', array(
	        'posts' => $posts,
	    ));
	}
}